package org.qrd.openmayyam;

import java.io.File;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

	/**
	 * The bundle that starts the servlet container
	 * @author Adarsh
	 * @author Sivaraman
	 */

public class Container implements BundleActivator{
	
   
    /**
     * The MainThread class listens for the WAR files . 
     * The instance for the class MainThread. 
     * This object is used to invoke the start() method of the MainThread class.  
     */
	
    MainThread mainThread;
    
    /**
     * Bundle context of the bundle ( assigned by OSGi implementation )
     */
    
    public static BundleContext bc = null;
    
    /**
     * (non-Javadoc)
     * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
     * The start method starts the bundle and calls the thread that listens for new WARs.
     */
    
    public void start(BundleContext arg0) throws Exception {
    	Container.bc=arg0;
    	this.mainThread =new MainThread();
    	this.mainThread.run(arg0);
    	this.mainThread.start();
    }
	
    /**
     * (non-Javadoc)
     * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
     * The stop method stops the mainThread thread and stops the bundle
     */
    
    public void stop(BundleContext arg0) throws Exception {
	    this.mainThread.stopThread();
	    this.mainThread.join();
	    Container.bc=null;
	}
}

